package com.smcaiot.filesync.starter.handler.impl;

import com.smcaiot.filesync.starter.app.FileSyncProperties;
import com.smcaiot.filesync.starter.entity.RemoteInfo;
import com.smcaiot.filesync.starter.handler.FileHandler;
import com.smcaiot.filesync.starter.handler.SyncFinishHandler;
import com.smcaiot.filesync.starter.util.FilenameUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.Map;
import java.util.Objects;

/**
 * @Author: cz
 * @Date: 2023/6/30
 * @Description: 不要在此类及其子类方法上加事务或者可增强类的注解，否则会找不到泛型
 */
public abstract class BaseHandler<T> implements SyncFinishHandler<T> {

    protected RemoteInfo remoteInfo;
    @Autowired
    protected FileHandler fileHandler;
    @Autowired
    protected FileSyncProperties fileSyncProp;

    protected String getNameByPath(String path) {
        return FilenameUtils.getName(path);
    }

    protected Map<String, String> getHeaderMap() {
        return Objects.isNull(remoteInfo) ? null : remoteInfo.getHeaderMap();
    }

    protected void setRemoteInfo(RemoteInfo remoteInfo) {
        this.remoteInfo = remoteInfo;
    }

}
